/*
 * Project Name spring-boot-tools
 * File Name AbstractMessageAction
 * Package Name com.huxiaosu.tools.cmpp.service
 * Create Time 2024/4/20
 * Create by name：liujie
 */
package com.huxiaosu.tools.mina.action;

import com.huxiaosu.tools.mina.cache.CacheService;
import com.huxiaosu.tools.mina.model.BaseMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Description
 *
 * @author liujie
 * @date 2024/4/20 10:52
 */
@Slf4j
public abstract class AbstractMessageAction implements MessageAction {

    @Autowired
    protected CacheService cacheService;
    /**
     * 获取 commandId

     * @return byte
     * @author liujie
     * @date 2024/7/9 13:08
     */
    @Override
    public abstract byte getMessageCommandId();
    /**
     * 获取 commandName

     * @return String
     * @author liujie
     * @date 2024/7/9 13:08
     */
    @Override
    public abstract String getMessageCommandName();

    /**
     * 执行方法

     * @return void
     * @author liujie
     * @date 2024/7/9 13:09
     */
    public abstract void execute();

    protected IoSession session;

    protected BaseMessage message;

    public void beforeExecute(IoSession session, BaseMessage baseMessage) {
        this.session = session;
        this.message = baseMessage;
    }
    @Override
    public void executeAction(IoSession session, BaseMessage baseMessage) {
        beforeExecute(session, baseMessage);
        this.execute();
        afterExecute(baseMessage);
    }

    public void afterExecute(BaseMessage baseMessage) {

    }

}
